package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.LinkedProblem;

/**
 * @author tzp
 * @since 2020/10/13
 */
public class ListNode implements LinkedProblem {
    public int val;
    public ListNode next;

    public ListNode() {
    }

    ListNode(int x) {
        val = x;
    }

    @Override
    public String toString() {
        return "{" + val + ",nxt=" + next + '}';
    }

    public static ListNode arrayToListNode(int[] a) {
        ListNode root = new ListNode(a[0]);
        ListNode pre = root;
        for (int i = 1; i < a.length; i++) {
            ListNode cur = new ListNode(a[i]);
            pre.next = cur;
            pre = cur;
        }
        return root;
    }
}
